<template>
    <div>
{{ fullName }} <br>
全名：<input type="text" v-model="fullName">
<p>{{  fullName2}}</p>
    </div>
</template>

<script setup>
import { ref, computed } from 'vue'

const firstName = ref('John')
const lastName = ref('Doe')

const fullName = computed({
  // getter
  get() {
    return firstName.value + '-' + lastName.value
  },
  // setter
  set(newValue) {
    // 注意：我们这里使用的是解构赋值语法
    console.log(newValue);
    // [firstName.value, lastName.value] = newValue.split('-')
    const arr = newValue.split('-')
    firstName.value=arr[0]
    lastName.value=arr[1]
  }
})

//常用的简单写法
const fullName2 = computed(() => {
    return firstName.value + '-' + lastName.value
})
</script>

<style  scoped>

</style>

